﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace QL_Truong_Hoc.HocTap
{
    public partial class frmHocSinhChiTiet : DevExpress.XtraEditors.XtraForm
    {
        private int mintHsID;
        private string mstrHoTen;
        DTO.THocSinhDTO mobjHS;
        DTO.THocSinhAnhDTO mobjAnh;
        DTO.TDanhSachDuTuyenDTO mobjDS;

        public frmHocSinhChiTiet(int intHsID)
        {
            InitializeComponent();
            mintHsID = intHsID;
        }

        private void frmHocSinhChiTiet_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'qLTHDataSet.mDiaDanh' table. You can move, or remove it, as needed.
            this.mDiaDanhTableAdapter.Fill(this.qLTHDataSet.mDiaDanh);
            // TODO: This line of code loads data into the 'qLTHDataSet.mDanToc' table. You can move, or remove it, as needed.
            this.mDanTocTableAdapter.Fill(this.qLTHDataSet.mDanToc);
            // TODO: This line of code loads data into the 'qLTHDataSet.mMonVanHoa' table. You can move, or remove it, as needed.
            this.mMonVanHoaTableAdapter.Fill(this.qLTHDataSet.mMonVanHoa);
            // TODO: This line of code loads data into the 'qLTHDataSet.mKhoaHoc' table. You can move, or remove it, as needed.
            this.mKhoaHocTableAdapter.Fill(this.qLTHDataSet.mKhoaHoc);
            // TODO: This line of code loads data into the 'qLTHDataSet.mKhoa' table. You can move, or remove it, as needed.
            this.mKhoaTableAdapter.Fill(this.qLTHDataSet.mKhoa);
            // TODO: This line of code loads data into the 'qLTHDataSet.mNghe' table. You can move, or remove it, as needed.
            this.mNgheTableAdapter.Fill(this.qLTHDataSet.mNghe);
            // TODO: This line of code loads data into the 'qLTHDataSet.mTrinhDoDaoTao' table. You can move, or remove it, as needed.
            this.mTrinhDoDaoTaoTableAdapter.Fill(this.qLTHDataSet.mTrinhDoDaoTao);
            // TODO: This line of code loads data into the 'qLTHDataSet.mTrinhDoVanHoa' table. You can move, or remove it, as needed.
            this.mTrinhDoVanHoaTableAdapter.Fill(this.qLTHDataSet.mTrinhDoVanHoa);
            // TODO: This line of code loads data into the 'qLTHDataSet.mCapBac' table. You can move, or remove it, as needed.
            this.mCapBacTableAdapter.Fill(this.qLTHDataSet.mCapBac);
            // TODO: This line of code loads data into the 'qLTHDataSet.mDonViQuanDoi' table. You can move, or remove it, as needed.
            this.mDonViQuanDoiTableAdapter.Fill(this.qLTHDataSet.mDonViQuanDoi);
            // TODO: This line of code loads data into the 'qLTHDataSet.mDoiTuongUuTien' table. You can move, or remove it, as needed.
            this.mDoiTuongUuTienTableAdapter.Fill(this.qLTHDataSet.mDoiTuongUuTien);

            this.tHocSinhMon_GetFull_ByHsIDTableAdapter.Fill(this.qLTHDataSet.tHocSinhMon_GetFull_ByHsID, mintHsID);
            this.usrProc_GetDiemMonVanHoa_ByHsIDTableAdapter.Fill(this.qLTHDataSet.usrProc_GetDiemMonVanHoa_ByHsID, mintHsID);

            xLoadDetail();
            xLoadNhapHoc();

            dgvDiemVanHoa.BestFitColumns();
            this.Text = "Thông tin học sinh " + mstrHoTen;

            //cho phép sửa điểm tổng kết tùy theo trình độ văn hóa.
            if (mobjHS.TDVH_ID >= (int)clsEnum.CAP_DO_VAN_HOA.LOP10) { colLop10_diemtongket.OptionsColumn.AllowEdit = true; }
            if (mobjHS.TDVH_ID >= (int)clsEnum.CAP_DO_VAN_HOA.LOP11) { colLop11_diemtongket.OptionsColumn.AllowEdit = true; }
            if (mobjHS.TDVH_ID >= (int)clsEnum.CAP_DO_VAN_HOA.LOP12) { colLop12_diemtongket.OptionsColumn.AllowEdit = true; }
        }

        private void mniSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                int intTemp;
                DTO.THocSinhMonVanHoaDTO objLop10_Van = null;
                DTO.THocSinhMonVanHoaDTO objLop10_Toan = null;
                DTO.THocSinhMonVanHoaDTO objLop10_Ly = null;
                DTO.THocSinhMonVanHoaDTO objLop10_Hoa = null;
                DTO.THocSinhMonVanHoaDTO objLop11_Van = null;
                DTO.THocSinhMonVanHoaDTO objLop11_Toan = null;
                DTO.THocSinhMonVanHoaDTO objLop11_Ly = null;
                DTO.THocSinhMonVanHoaDTO objLop11_Hoa = null;
                DTO.THocSinhMonVanHoaDTO objLop12_Van = null;
                DTO.THocSinhMonVanHoaDTO objLop12_Toan = null;
                DTO.THocSinhMonVanHoaDTO objLop12_Ly = null;
                DTO.THocSinhMonVanHoaDTO objLop12_Hoa = null;

                //check valid trước khi tiếp tục
                if (!validControlBlank.Validate()) return;

                if (!clsCommon.fncMsgConfirm("Dữ liệu sẽ được lưu. Bạn có chắc chắn?")) return;

                Cursor.Current = Cursors.WaitCursor;

                //khai báo đối tượng
                DTO.THocSinhDTO objHocSinh = DAO.THocSinhDAO.Select(Program.gobjDb, mintHsID);
                DTO.TDanhSachDuTuyenDTO objDuTuyen = DAO.TDanhSachDuTuyenDAO.Select(Program.gobjDb, mintHsID);

                //đối tượng học sinh
                #region Lấy dữ liệu
                objHocSinh.HS_ID = mintHsID;
                objHocSinh.Hs_hodem = txtHoDem.Text.Trim();
                objHocSinh.Hs_ten = txtTen.Text.Trim();
                objHocSinh.Hs_gioitinh = clsCommon.fncCnvBoolToInt(rdGioiTinh.EditValue);
                objHocSinh.Hs_ngaysinh = clsCommon.fncCnvNullToDatetime(dtpNgaySinh.EditValue);
                objHocSinh.Hs_quequan = txtQueQuan.Text.Trim();
                objHocSinh.DD_ID = clsCommon.fncCnvNullToString(txtDiaDanh.EditValue);
                objHocSinh.Hs_hokhau = txtThuongTru.Text.Trim();
                objHocSinh.Hs_tenthuonggoi = txtTenThuongGoi.Text.Trim();
                objHocSinh.Hs_noisinh = txtNoiSinh.Text.Trim();

                objHocSinh.DV_ID = clsCommon.fncCnvNullToInt(lokDonVi.EditValue);
                objHocSinh.CB_ID = clsCommon.fncCnvNullToInt(lokCapBac.EditValue);
                objHocSinh.Hs_ngayvaodang = clsCommon.fncCnvNullToDatetime(dtpNgayVaoDang.EditValue);
                objHocSinh.Hs_ngayvaodoan = clsCommon.fncCnvNullToDatetime(dtpNgayVaoDoan.EditValue);
                objHocSinh.Hs_dantoc = txtDanToc.Text.Trim();

                objHocSinh.TDVH_ID = clsCommon.fncCnvNullToInt(lokTrinhDoVanHoa.EditValue);
                intTemp = (int)txtNamTotNghiep.Value; if (intTemp > 0) objHocSinh.Hs_namtotnghiep = intTemp;
                objHocSinh.Hs_noitotnghiep = txtNoiTotNghiep.Text.Trim();
                objHocSinh.Hs_uutien = clsCommon.fncCnvNullToString(lokDoiTuongUuTien.EditValue);
                objHocSinh.Hs_cmnd = txtCMND.Text.Trim();

                objHocSinh.Hs_cmnd_ngaycap = clsCommon.fncCnvNullToDatetime(dtpNgaySinh.EditValue);
                objHocSinh.Hs_cmnd_noicap = txtCMND_NoiCap.Text.Trim();
                objHocSinh.Hs_hotencha = txtHoTenBo.Text.Trim();
                objHocSinh.Hs_hotenme = txtHoTenMe.Text.Trim();
                objHocSinh.Hs_diachilienlac = txtDiaChiLienLac.Text.Trim();

                objHocSinh.Hs_dienthoainr = txtDTNR.Text.Trim();
                objHocSinh.Hs_dienthoaidd = txtDTDD.Text.Trim();

                objHocSinh.Hs_tongiao = txtTonGiao.Text.Trim();
                objHocSinh.Hs_nghenghiepcha = txtNgheNghiepBo.Text.Trim();
                objHocSinh.Hs_nghenghiepme = txtNgheNghiepMe.Text.Trim();
                objHocSinh.Hs_nghenghiepvochong = txtNgheNghiepVoChong.Text.Trim();
                objHocSinh.Hs_hotenvochong = txtHoTenVoChong.Text.Trim();

                objHocSinh.Hs_cmnd = txtCMND.Text.Trim();
                objHocSinh.Hs_cmnd_ngaycap = clsCommon.fncCnvNullToDatetime(dtpCMND_NgayCap.EditValue);
                objHocSinh.Hs_cmnd_noicap = txtCMND_NoiCap.Text.Trim();
                objHocSinh.Hs_ngayvaodangCT = clsCommon.fncCnvNullToDatetime(dtpNgayVaoDangChinhThuc.EditValue);
                objHocSinh.Hs_nguyenvongsaukhihoc = txtLamViecSauRaTruong.Text.Trim();
                objHocSinh.Hs_coviecsautotnghiep = chkDaCoViecSauRaTruong.Checked;
                objHocSinh.Hs_khaosattruockhihoc = chkDaKhaoSatTruoc.Checked;

                //thông tin dự tuyển
                objDuTuyen.HS_ID = mintHsID;
                objDuTuyen.NamTuyenSinh = clsCommon.fncCnvNullToInt(txtNamTuyenSinh.Text.Trim());
                objDuTuyen.DotTuyenSinh = txtDotTuyenSinh.Text.Trim();
                objDuTuyen.TD_ID = clsCommon.fncCnvNullToInt(lokTrinhDoDaoTao.EditValue);
                objDuTuyen.NG_ID1 = clsCommon.fncCnvNullToInt(lokNV1.EditValue);
                objDuTuyen.NG_ID2 = clsCommon.fncCnvNullToInt(lokNV2.EditValue);

                int i = 0; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.PhieuHocNghe = true; } else { objDuTuyen.PhieuHocNghe = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.TheHocNghe = true; } else { objDuTuyen.TheHocNghe = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.QuyetDinhXuatNgu = true; } else { objDuTuyen.QuyetDinhXuatNgu = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.PhieuQuanNhan = true; } else { objDuTuyen.PhieuQuanNhan = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.CMND = true; } else { objDuTuyen.CMND = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.BangVanHoa = true; } else { objDuTuyen.BangVanHoa = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.BanSaoGiayKhaiSinh = true; } else { objDuTuyen.BanSaoGiayKhaiSinh = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.Anh = true; } else { objDuTuyen.Anh = false; }
                i++; if (chkPhieu.Items[i].CheckState == System.Windows.Forms.CheckState.Checked) { objDuTuyen.DaCapVPP = true; } else { objDuTuyen.DaCapVPP = false; }

                objDuTuyen.QuyetDinhXuatNgu_So = "";
                objDuTuyen.QuyetDinhXuatNgu_Ngay = DateTime.MinValue;
                objDuTuyen.TheHocNghe_So = "";
                objDuTuyen.TheHocNghe_Ngay = DateTime.MinValue;

                if (objDuTuyen.QuyetDinhXuatNgu)
                {
                    objDuTuyen.QuyetDinhXuatNgu_So = txtQDXN_So.Text.Trim();
                    objDuTuyen.QuyetDinhXuatNgu_Ngay = clsCommon.fncCnvNullToDatetime(dtpQDXN_Ngay.EditValue);
                }

                if (objDuTuyen.TheHocNghe)
                {
                    objDuTuyen.TheHocNghe_So = txtTheHocNghe_So.Text.Trim();
                    objDuTuyen.TheHocNghe_Ngay = clsCommon.fncCnvNullToDatetime(dtpTheHocNghe_Ngay.EditValue);
                }
                #endregion

                bool blnSuccess = true;

                //lưu điểm văn hóa tùy theo trình độ văn hóa
                #region Lấy Điểm tổng kết văn hóa

                if (colLop10_diemtongket.OptionsColumn.AllowEdit)
                {
                    objLop10_Van = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.VAN, (int)clsEnum.CAP_DO_VAN_HOA.LOP10);
                    objLop10_Toan = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.TOAN, (int)clsEnum.CAP_DO_VAN_HOA.LOP10);
                    objLop10_Ly = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.LY, (int)clsEnum.CAP_DO_VAN_HOA.LOP10);
                    objLop10_Hoa = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.HOA, (int)clsEnum.CAP_DO_VAN_HOA.LOP10);

                    objLop10_Van.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(0, colLop10_diemtongket));
                    objLop10_Toan.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(1, colLop10_diemtongket));
                    objLop10_Ly.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(2, colLop10_diemtongket));
                    objLop10_Hoa.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(3, colLop10_diemtongket));

                    objLop10_Van.Diemcodinh = true;
                    objLop10_Toan.Diemcodinh = true;
                    objLop10_Ly.Diemcodinh = true;
                    objLop10_Hoa.Diemcodinh = true;
                }

                if (colLop11_diemtongket.OptionsColumn.AllowEdit)
                {
                    objLop11_Van = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.VAN, (int)clsEnum.CAP_DO_VAN_HOA.LOP11);
                    objLop11_Toan = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.TOAN, (int)clsEnum.CAP_DO_VAN_HOA.LOP11);
                    objLop11_Ly = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.LY, (int)clsEnum.CAP_DO_VAN_HOA.LOP11);
                    objLop11_Hoa = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.HOA, (int)clsEnum.CAP_DO_VAN_HOA.LOP11);

                    objLop11_Van.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(0, colLop11_diemtongket));
                    objLop11_Toan.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(1, colLop11_diemtongket));
                    objLop11_Ly.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(2, colLop11_diemtongket));
                    objLop11_Hoa.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(3, colLop11_diemtongket));

                    objLop11_Van.Diemcodinh = true;
                    objLop11_Toan.Diemcodinh = true;
                    objLop11_Ly.Diemcodinh = true;
                    objLop11_Hoa.Diemcodinh = true;
                }

                if (colLop12_diemtongket.OptionsColumn.AllowEdit)
                {
                    objLop12_Van = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.VAN, (int)clsEnum.CAP_DO_VAN_HOA.LOP12);
                    objLop12_Toan = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.TOAN, (int)clsEnum.CAP_DO_VAN_HOA.LOP12);
                    objLop12_Ly = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.LY, (int)clsEnum.CAP_DO_VAN_HOA.LOP12);
                    objLop12_Hoa = DAO.THocSinhMonVanHoaDAO.Select(Program.gobjDb, mintHsID, (int)clsEnum.MON_VAN_HOA.HOA, (int)clsEnum.CAP_DO_VAN_HOA.LOP12);

                    objLop12_Van.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(0, colLop12_diemtongket));
                    objLop12_Toan.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(1, colLop12_diemtongket));
                    objLop12_Ly.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(2, colLop12_diemtongket));
                    objLop12_Hoa.Diemtongket = clsCommon.fncCnvNullToFloat(dgvDiemVanHoa.GetRowCellValue(3, colLop12_diemtongket));

                    objLop12_Van.Diemcodinh = true;
                    objLop12_Toan.Diemcodinh = true;
                    objLop12_Ly.Diemcodinh = true;
                    objLop12_Hoa.Diemcodinh = true;
                }
                #endregion

                //objConn.Open();
                Program.gobjTrans = Program.gobjConn.BeginTransaction();

                try
                {
                    blnSuccess = blnSuccess && DAO.THocSinhDAO.Update(Program.gobjDb, Program.gobjTrans, objHocSinh);
                    blnSuccess = blnSuccess && DAO.TDanhSachDuTuyenDAO.Update(Program.gobjDb, Program.gobjTrans, objDuTuyen);

                    #region Lưu điểm tổng kết
                    if (colLop10_diemtongket.OptionsColumn.AllowEdit)
                    {
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop10_Van);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop10_Toan);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop10_Ly);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop10_Hoa);
                    }

                    if (colLop11_diemtongket.OptionsColumn.AllowEdit)
                    {
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop11_Van);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop11_Toan);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop11_Ly);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop11_Hoa);
                    }

                    if (colLop12_diemtongket.OptionsColumn.AllowEdit)
                    {
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop12_Van);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop12_Toan);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop12_Ly);
                        blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Update(Program.gobjDb, Program.gobjTrans, objLop12_Hoa);
                    }
                    #endregion

                    //commit dữ liệu nếu không có gì lỗi, ngược lại thì rollback
                    if (blnSuccess)
                    {
                        Program.gobjTrans.Commit();
                    }
                    else
                    { Program.gobjTrans.Rollback(); }
                }
                catch
                {
                    Program.gobjTrans.Rollback();
                }

                if (blnSuccess)
                    clsCommon.fncMsgInfo("Cập nhật hồ sơ thành công.");
                else
                    clsCommon.fncMsgInfo("Cập nhật hồ sơ thất bại.");
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally { Cursor.Current = Cursors.Default; }
        }

        private bool xLoadDetail()
        {
            bool blnResult = false;
            try
            {
                mobjHS = DAO.THocSinhDAO.Select(Program.gobjDb, mintHsID);
                mobjAnh = DAO.THocSinhAnhDAO.Select(Program.gobjDb, mintHsID);

                txtHoDem.Text = mobjHS.Hs_hodem;
                txtTen.Text = mobjHS.Hs_ten;
                mstrHoTen = mobjHS.Hs_hodem + " " + mobjHS.Hs_ten;
                rdGioiTinh.EditValue = clsCommon.fncCnvNullToBool(mobjHS.Hs_gioitinh);
                txtTenThuongGoi.Text = mobjHS.Hs_tenthuonggoi;
                if (mobjHS.Hs_ngaysinh > DateTime.MinValue) dtpNgaySinh.EditValue = mobjHS.Hs_ngaysinh;

                txtNoiSinh.Text = mobjHS.Hs_noisinh;
                txtQueQuan.Text = mobjHS.Hs_quequan;
                txtDiaDanh.EditValue = mobjHS.DD_ID;
                txtThuongTru.Text = mobjHS.Hs_hokhau;
                txtDanToc.Text = mobjHS.Hs_dantoc;
                txtTonGiao.Text = mobjHS.Hs_tongiao;

                lokTrinhDoVanHoa.EditValue = mobjHS.TDVH_ID;
                if (mobjHS.Hs_ngayvaodang > DateTime.MinValue) dtpNgayVaoDang.EditValue = mobjHS.Hs_ngayvaodang;
                if (mobjHS.Hs_ngayvaodangCT > DateTime.MinValue) dtpNgayVaoDangChinhThuc.EditValue = mobjHS.Hs_ngayvaodangCT;
                if (mobjHS.Hs_ngayvaodoan > DateTime.MinValue) dtpNgayVaoDoan.EditValue = mobjHS.Hs_ngayvaodoan;

                txtHoTenBo.Text = mobjHS.Hs_hotencha;
                txtHoTenMe.Text = mobjHS.Hs_hotenme;
                txtHoTenVoChong.Text = mobjHS.Hs_hotenvochong;
                txtNgheNghiepBo.Text = mobjHS.Hs_nghenghiepcha;
                txtNgheNghiepMe.Text = mobjHS.Hs_nghenghiepme;
                txtNgheNghiepVoChong.Text = mobjHS.Hs_nghenghiepvochong;

                lokDoiTuongUuTien.EditValue = mobjHS.Hs_uutien;
                txtDiaChiLienLac.Text = mobjHS.Hs_diachilienlac;
                txtDTDD.Text = mobjHS.Hs_dienthoaidd;
                txtDTNR.Text = mobjHS.Hs_dienthoainr;
                txtLamViecSauRaTruong.Text = mobjHS.Hs_nguyenvongsaukhihoc;
                chkDaCoViecSauRaTruong.Checked = mobjHS.Hs_coviecsautotnghiep;
                chkDaKhaoSatTruoc.Checked = mobjHS.Hs_khaosattruockhihoc;

                lokDonVi.EditValue = mobjHS.DV_ID;
                lokCapBac.EditValue = mobjHS.CB_ID;
                txtCMND.Text = mobjHS.Hs_cmnd;
                txtCMND_NoiCap.Text = mobjHS.Hs_cmnd_noicap;
                if (mobjHS.Hs_cmnd_ngaycap > DateTime.MinValue) dtpCMND_NgayCap.EditValue = mobjHS.Hs_cmnd_ngaycap;
                txtNoiTotNghiep.Text = mobjHS.Hs_noitotnghiep;
                txtNamTotNghiep.Value = mobjHS.Hs_namtotnghiep;

                //ảnh đại diện
                if (mobjAnh.Hs_anhdaidien != null)
                {
                    ImageConverter ic = new ImageConverter();
                    pbAvatar.Image = (Image)ic.ConvertFrom(mobjAnh.Hs_anhdaidien);
                }
                return true;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            return blnResult;
        }

        private bool xLoadNhapHoc()
        {
            bool blnResult = false;
            try
            {
                mobjDS = DAO.TDanhSachDuTuyenDAO.Select(Program.gobjDb, mintHsID);

                txtNamTuyenSinh.Text = mobjDS.NamTuyenSinh.ToString();
                txtDotTuyenSinh.Text = mobjDS.DotTuyenSinh;
                lokTrinhDoDaoTao.EditValue = mobjDS.TD_ID;
                lokNV1.EditValue = mobjDS.NG_ID1;
                lokNV2.EditValue = mobjDS.NG_ID2;

                lokNghe.EditValue = mobjDS.NG_ID;
                
                int i = 0; if (mobjDS.PhieuHocNghe) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.TheHocNghe) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.QuyetDinhXuatNgu) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.PhieuQuanNhan) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.CMND) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.BangVanHoa) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.BanSaoGiayKhaiSinh) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.Anh) chkPhieu.Items[i].CheckState = CheckState.Checked;
                i++; if (mobjDS.DaCapVPP) chkPhieu.Items[i].CheckState = CheckState.Checked;

                txtQDXN_So.Text = mobjDS.QuyetDinhXuatNgu_So;
                if (mobjDS.QuyetDinhXuatNgu_Ngay > DateTime.MinValue) dtpQDXN_Ngay.EditValue = mobjDS.QuyetDinhXuatNgu_Ngay;
                txtTheHocNghe_So.Text = mobjDS.TheHocNghe_So;
                if (mobjDS.TheHocNghe_Ngay > DateTime.MinValue) dtpTheHocNghe_Ngay.EditValue = mobjDS.TheHocNghe_Ngay;

                //thông tin khung đào tạo
                DataTable objData = DAO.clsDbAccess.fncGetTrinhDo_Khoa_Khoas_Nghe_HocSinh(Program.gobjDb, string.Format("tLopHocSinh.HS_ID = {0}", mintHsID));
                if (objData != null)
                {
                    lokKhoa.EditValue = clsCommon.fncCnvNullToInt(objData.Rows[0]["KH_ID"]);
                    lokKhoas.EditValue = clsCommon.fncCnvNullToInt(objData.Rows[0]["KHS_ID"]);
                    lokNghe.EditValue = clsCommon.fncCnvNullToInt(objData.Rows[0]["NG_ID"]);
                    txtLop.Text = clsCommon.fncCnvNullToString(objData.Rows[0]["Lop_ten"]);
                }

                return true;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            return blnResult;
        }
        
        private void btnLuuAnh_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                DTO.THocSinhAnhDTO objAnh = new DTO.THocSinhAnhDTO();
                objAnh.HS_ID = mintHsID;
                objAnh.Hs_anhdaidien = clsCommon.fncCnvImageToByte(pbAvatar.Image);

                DAO.THocSinhAnhDAO.Delete(Program.gobjDb, Program.gobjTrans, mintHsID);
                DAO.THocSinhAnhDAO.Insert(Program.gobjDb, Program.gobjTrans, objAnh);

                clsCommon.fncMsgInfo("Đã lưu ảnh đại diện.");
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally { Cursor.Current = Cursors.Default; }
        }

        private void btnXoaAnh_Click(object sender, EventArgs e)
        {
            try
            {
                pbAvatar.Image = null;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void chkPhieu_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            try
            {
                if (chkPhieu.Items[1].CheckState == System.Windows.Forms.CheckState.Checked)
                    grpTheHocNghe.Enabled = true;
                else
                    grpTheHocNghe.Enabled = false;

                if (chkPhieu.Items[2].CheckState == System.Windows.Forms.CheckState.Checked)
                    grpQDXuatNgu.Enabled = true;
                else
                    grpQDXuatNgu.Enabled = false;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void pbAvatar_Click(object sender, EventArgs e)
        {
            try
            {
                if (dlgOpenImage.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

                using (Tools.CatAnh.frmCatAnh objAnh = new Tools.CatAnh.frmCatAnh(dlgOpenImage.FileName))
                {
                    objAnh.ShowDialog();
                    if (!objAnh.ImageSelected) return;

                    pbAvatar.Image = objAnh.ImageHS;
                }
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void txtHoDem_Leave(object sender, EventArgs e)
        {
            try
            {
                DevExpress.XtraEditors.TextEdit objText = (DevExpress.XtraEditors.TextEdit)sender;
                objText.Text = clsCommon.fncCapitalizeFirst(objText.Text.Trim());
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

    }
}